package com.sunspring.zdcall.websockt;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * @Author WuLei
 * @Date 2018/11/26  15:33
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    /**
     * 注册端点
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //客户端连接的webSocket端点
        registry.addEndpoint("/zd-queuing-websocket").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //服务端推送消息给客户端地址前缀
        registry.enableSimpleBroker("/newPatient/dept",
                "/newPatient/checkRoom",
                "/pass/dept",
                "/pass/checkRoom",
                "/call/dept",
                "/call/checkRoom",
                "/finish/dept",
                "/finish/checkRoom",
                "/zd-call/cleanCache",
                "/printPro/");
        //客户端访问服务端地址前缀
        registry.setApplicationDestinationPrefixes("/zd-server");
    }
}
